package com.jlect.swebing.ui.client.button;

import com.jlect.swebing.renderers.client.ToggleButtonRenderer;
import com.jlect.swebing.ui.client.ChangeEvent;
import com.jlect.swebing.ui.client.GComponent;

/**
 * Default button view implementation.
 *
 * @author Sergey Kozmin
 * @since 23.11.2007 9:45:23
 */
public class ToggleButtonViewImpl extends DefaultButtonViewImpl {
    public ToggleButtonViewImpl(GComponent component) {
        super(component);
    }

    public ToggleButtonRenderer getToggleRenderer() {
        return (ToggleButtonRenderer) getButtonRenderer();
    }

    public void changePerformed(ChangeEvent e) {
        super.changePerformed(e);
        int type = e.getChangeType();
        switch(type) {
            case ChangeEvent.STATE_CHANGED_EVENT : {
                getToggleRenderer().setPressed(getModel().isPressed());
                break;
            }
            case ChangeEvent.SELECTION_CHANGED_EVENT : {
                getToggleRenderer().setSelected(getModel().isSelected());
                break;
            }
        }
    }
}